import request from '../../utils/request';

export interface TaskVO {
  id: string;
  name: string;
  processInstanceId: string;
  processDefinitionId: string;
  assignee: string;
  createTime: string;
  dueDate?: string;
  priority: number;
  description?: string;
  formKey?: string;
  category?: string;
  suspended: boolean;
}

export interface TaskApprovalVO {
  id: string;
  comment: string;
  approve: boolean;
  variables?: Record<string, any>;
}

// BPM 任务管理 API
export const TaskApi = {
  // 查询待办任务分页
  getTaskTodoPage: async (params: any) => {
    return await request.get('/bpm/task/todo-page', { params });
  },

  // 查询已办任务分页
  getTaskDonePage: async (params: any) => {
    return await request.get('/bpm/task/done-page', { params });
  },

  // 查询管理任务分页
  getTaskManagerPage: async (params: any) => {
    return await request.get('/bpm/task/manager-page', { params });
  },

  // 审批任务
  approveTask: async (data: TaskApprovalVO) => {
    return await request.put('/bpm/task/approve', data);
  },

  // 拒绝任务
  rejectTask: async (data: TaskApprovalVO) => {
    return await request.put('/bpm/task/reject', data);
  },

  // 根据流程实例ID查询任务列表
  getTaskListByProcessInstanceId: async (processInstanceId: string) => {
    return await request.get(`/bpm/task/list-by-process-instance-id?processInstanceId=${processInstanceId}`);
  },

  // 获取所有可退回的节点
  getTaskListByReturn: async (id: string) => {
    return await request.get('/bpm/task/list-by-return', { params: { id } });
  },

  // 退回任务
  returnTask: async (data: any) => {
    return await request.put('/bpm/task/return', data);
  },

  // 委派任务
  delegateTask: async (data: any) => {
    return await request.put('/bpm/task/delegate', data);
  },

  // 转派任务
  transferTask: async (data: any) => {
    return await request.put('/bpm/task/transfer', data);
  },

  // 加签任务
  signCreateTask: async (data: any) => {
    return await request.put('/bpm/task/create-sign', data);
  }
};